/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bff.spi;

import com.inspur.edp.bef.api.action.VoidActionResult;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bff.api.manager.IFSAction;
import com.inspur.edp.bff.api.manager.IFSManagerContext;
import lombok.Getter;

/**
 * FormServer操作基类，所有FormServer操作继承自该类。
 * 实现接口{@link IFSAction<TResult>
 * 如果操作没有返回值，则指定返回值类型为 {@link VoidActionResult }}
 */
public abstract class AbstractFSAction<TResult> implements IFSAction<TResult> {

    /**
     * FormServer管理器上下文。
     */
    @Getter
    private IFSManagerContext context;
    private TResult result;
    private boolean hasSetValue = false;

    protected AbstractFSAction() {
    }

    protected boolean getIsAutoSave() {
        return false;
    }

    /**
     * 获取BELcp
     *
     * @return 得到的BELcp
     * @see IStandardLcp
     */
    protected final IStandardLcp getLcp() {
        return getContext().getLcp();
    }


    public final TResult deal(IFSManagerContext context) {
        this.context = context;
        execute();
        //if(IsAutoSave)
        //    GetLcp().Save();
        return getResult();
    }

    /**
     * 获取或设置自定义动作的返回值，返回值类型为TResult
     */
    protected final TResult getResult() {
        return result;
    }

    protected final void setResult(TResult value) {
        result = value;

        hasSetValue = true;
    }

    /**
     * 自定义动作的核心逻辑抽象方法，该方法需要开发人员在实现类中复写并添加实现逻辑
     */
    protected abstract void execute();
}
